<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="人员编号" prop="memberNo">
        <el-input
          v-model="queryParams.memberNo"
          placeholder="请输入人员编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="昵称" prop="realName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="gender">
        <el-select v-model="queryParams.gender" placeholder="请选择性别" clearable>
          <el-option label="男" value="0" />
          <el-option label="女" value="1" />
        </el-select>
      </el-form-item>
      <el-form-item label="手机号码" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="城市" prop="city">
        <el-input
          v-model="queryParams.city"
          placeholder="请输入城市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="memberStatus">
        <el-select v-model="queryParams.memberStatus" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.dating_member_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['dating:member:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['dating:member:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['dating:member:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['dating:member:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['dating:member:import']"
        >导入</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="memberList"
      @selection-change="handleSelectionChange"
      @row-dblclick="handleRowDblClick"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="人员编号" align="center" prop="memberNo" />
      <el-table-column label="昵称" align="center" prop="nickName" />
      <el-table-column label="性别" align="center" prop="gender">
        <template slot-scope="scope">
          <span>{{ scope.row.gender === '0' ? '男' : '女' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="身高(cm)" align="center" prop="height" />
      <el-table-column label="手机号码" align="center" prop="phone" />
      <el-table-column label="城市" align="center" prop="city" >
        <template slot-scope="scope">
          <span>{{ scope.row.province }}-{{ scope.row.city }}</span>
        </template>
      </el-table-column>
      <el-table-column label="学历" align="center" prop="education" />
      <el-table-column label="月收入" align="center" prop="monthlyIncome" />
      <el-table-column label="状态" align="center" prop="memberStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.dating_member_status" :value="scope.row.memberStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="VIP等级" align="center" prop="vipLevel">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.vipLevel == 0" type="info">普通</el-tag>
          <el-tag v-else-if="scope.row.vipLevel == 1" type="warning">VIP1</el-tag>
          <el-tag v-else-if="scope.row.vipLevel == 2" type="success">VIP2</el-tag>
          <el-tag v-else type="danger">VIP3</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="注册日期" align="center" prop="registrationDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.registrationDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['dating:member:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(scope.row)"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-connection"
            @click="handleMatch(scope.row)"
            v-hasPermi="['dating:match:auto']"
          >匹配</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['dating:member:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改婚恋人员信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-tabs v-model="activeTab">
          <el-tab-pane label="基本信息" name="basic">
            <el-row>
<!--              <el-col :span="12">-->
<!--                <el-form-item label="人员编号" prop="memberNo">-->
<!--                  <el-input v-model="form.memberNo" placeholder="请输入人员编号" />-->
<!--                </el-form-item>-->
<!--              </el-col>-->
              <el-col :span="12">
                <el-form-item label="昵称" prop="nickName">
                  <el-input v-model="form.nickName" placeholder="请输入昵称" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="真实姓名" prop="realName">
                  <el-input v-model="form.realName" placeholder="请输入真实姓名" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="性别" prop="gender">
                  <el-radio-group v-model="form.gender">
                    <el-radio label="0">男</el-radio>
                    <el-radio label="1">女</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="出生日期" prop="birthDate">
                  <el-date-picker clearable
                    v-model="form.birthDate"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="请选择出生日期">
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="身高(cm)" prop="height">
                  <el-input v-model="form.height" placeholder="请输入身高" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="体重(kg)" prop="weight">
                  <el-input v-model="form.weight" placeholder="请输入体重" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="手机号码" prop="phone">
                  <el-input v-model="form.phone" placeholder="请输入手机号码" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="邮箱" prop="email">
                  <el-input v-model="form.email" placeholder="请输入邮箱" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="微信号" prop="wechat">
                  <el-input v-model="form.wechat" placeholder="请输入微信号" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="QQ号" prop="qq">
                  <el-input v-model="form.qq" placeholder="请输入QQ号" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-tab-pane>

          <el-tab-pane label="地址工作" name="work">
            <el-form-item label="所在地区" prop="regionIds">
              <region-select
                v-model="form.regionIds"
                mode="cascader"
                :level="3"
                placeholder="请选择省/市/区"
                @change="handleRegionChange"
              />
            </el-form-item>
            <el-form-item label="详细地址" prop="address">
              <el-input v-model="form.address" placeholder="请输入详细地址" />
            </el-form-item>
            <el-row>
              <el-col :span="12">
                <el-form-item label="学历" prop="education">
                  <el-select v-model="form.education" placeholder="请选择学历">
                    <el-option label="初中" value="初中" />
                    <el-option label="高中" value="高中" />
                    <el-option label="大专" value="大专" />
                    <el-option label="本科" value="本科" />
                    <el-option label="硕士" value="硕士" />
                    <el-option label="博士" value="博士" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="专业" prop="major">
                  <el-input v-model="form.major" placeholder="请输入专业" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="毕业院校" prop="school">
              <el-input v-model="form.school" placeholder="请输入毕业院校" />
            </el-form-item>
            <el-row>
              <el-col :span="12">
                <el-form-item label="工作单位" prop="workUnit">
                  <el-input v-model="form.workUnit" placeholder="请输入工作单位" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="职位" prop="position">
                  <el-input v-model="form.position" placeholder="请输入职位" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="月收入" prop="monthlyIncome">
                  <el-input v-model="form.monthlyIncome" placeholder="请输入月收入" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="年收入" prop="annualIncome">
                  <el-input v-model="form.annualIncome" placeholder="请输入年收入" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-tab-pane>

          <el-tab-pane label="个人情况" name="personal">
            <el-row>
              <el-col :span="12">
                <el-form-item label="婚恋状态" prop="maritalStatus">
                  <el-select v-model="form.maritalStatus" placeholder="请选择婚恋状态">
                    <el-option label="未婚" value="未婚" />
                    <el-option label="离异" value="离异" />
                    <el-option label="丧偶" value="丧偶" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="是否有子女" prop="hasChildren">
                  <el-radio-group v-model="form.hasChildren">
                    <el-radio label="0">无</el-radio>
                    <el-radio label="1">有</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="子女数量" prop="childrenCount" v-if="form.hasChildren === '1'">
              <el-input v-model="form.childrenCount" placeholder="请输入子女数量" />
            </el-form-item>
            <el-form-item label="性格描述" prop="personality">
              <el-input v-model="form.personality" type="textarea" placeholder="请输入性格描述" />
            </el-form-item>
            <el-form-item label="兴趣爱好" prop="hobbies">
              <el-input v-model="form.hobbies" type="textarea" placeholder="请输入兴趣爱好，多个用逗号分隔" />
            </el-form-item>
            <el-form-item label="自我介绍" prop="selfIntroduction">
              <el-input v-model="form.selfIntroduction" type="textarea" rows="4" placeholder="请输入自我介绍" />
            </el-form-item>
          </el-tab-pane>

          <el-tab-pane label="择偶要求" name="requirements">
            <el-row>
              <el-col :span="12">
                <el-form-item label="期望年龄" prop="mateAge">
                  <el-col :span="11">
                    <el-input v-model="form.mateAgeMin" placeholder="最小年龄" />
                  </el-col>
                  <el-col :span="2" style="text-align: center">-</el-col>
                  <el-col :span="11">
                    <el-input v-model="form.mateAgeMax" placeholder="最大年龄" />
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="期望身高" prop="mateHeight">
                  <el-col :span="11">
                    <el-input v-model="form.mateHeightMin" placeholder="最小身高" />
                  </el-col>
                  <el-col :span="2" style="text-align: center">-</el-col>
                  <el-col :span="11">
                    <el-input v-model="form.mateHeightMax" placeholder="最大身高" />
                  </el-col>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="期望学历" prop="mateEducation">
                  <el-select v-model="form.mateEducation" placeholder="请选择期望学历">
                    <el-option label="不限" value="" />
                    <el-option label="初中" value="初中" />
                    <el-option label="高中" value="高中" />
                    <el-option label="大专" value="大专" />
                    <el-option label="本科" value="本科" />
                    <el-option label="硕士" value="硕士" />
                    <el-option label="博士" value="博士" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="期望最低收入" prop="mateIncomeMin">
                  <el-input v-model="form.mateIncomeMin" placeholder="请输入期望最低收入" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="期望居住地" prop="mateLocation">
              <el-input v-model="form.mateLocation" placeholder="请输入期望居住地" />
            </el-form-item>
            <el-form-item label="其他择偶要求" prop="mateRequirement">
              <el-input v-model="form.mateRequirement" type="textarea" rows="4" placeholder="请输入其他择偶要求" />
            </el-form-item>
          </el-tab-pane>

          <el-tab-pane label="会员信息" name="vip">
            <el-row>
              <el-col :span="12">
                <el-form-item label="会员状态" prop="memberStatus">
                  <el-select v-model="form.memberStatus" placeholder="请选择会员状态">
                    <el-option
                      v-for="dict in dict.type.dating_member_status"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="VIP等级" prop="vipLevel">
                  <el-select v-model="form.vipLevel" placeholder="请选择VIP等级">
                    <el-option label="普通会员" :value="0" />
                    <el-option label="VIP1" :value="1" />
                    <el-option label="VIP2" :value="2" />
                    <el-option label="VIP3" :value="3" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="VIP到期日期" prop="vipExpireDate" v-if="form.vipLevel > 0">
              <el-date-picker clearable
                v-model="form.vipExpireDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择VIP到期日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入备注" />
            </el-form-item>
          </el-tab-pane>

          <el-tab-pane label="照片管理" name="photos">
            <el-form-item label="个人照片" prop="photos">
              <image-upload
                v-model="form.photos"
                :limit="6"
                :fileSize="10"
                :fileType="['png', 'jpg', 'jpeg']"
              />
              <div class="el-upload__tip">最多可上传6张个人照片，每张不超过10MB</div>
            </el-form-item>
          </el-tab-pane>
        </el-tabs>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 人员详情对话框 -->
    <el-dialog title="人员详情" :visible.sync="detailOpen" width="800px" append-to-body>
      <el-descriptions :column="2" border>
        <el-descriptions-item label="人员编号">{{ detailData.memberNo }}</el-descriptions-item>
        <el-descriptions-item label="昵称">{{ detailData.nickName }}</el-descriptions-item>
        <el-descriptions-item label="真实姓名">{{ detailData.realName }}</el-descriptions-item>
        <el-descriptions-item label="性别">{{ detailData.gender === '0' ? '男' : '女' }}</el-descriptions-item>
        <el-descriptions-item label="年龄">{{ detailData.age }}</el-descriptions-item>
        <el-descriptions-item label="身高">{{ detailData.height }}cm</el-descriptions-item>
        <el-descriptions-item label="体重">{{ detailData.weight }}kg</el-descriptions-item>
        <el-descriptions-item label="手机号码">{{ detailData.phone }}</el-descriptions-item>
        <el-descriptions-item label="邮箱">{{ detailData.email }}</el-descriptions-item>
        <el-descriptions-item label="城市">{{ detailData.city }}</el-descriptions-item>
        <el-descriptions-item label="学历">{{ detailData.education }}</el-descriptions-item>
        <el-descriptions-item label="工作单位">{{ detailData.workUnit }}</el-descriptions-item>
        <el-descriptions-item label="职位">{{ detailData.position }}</el-descriptions-item>
        <el-descriptions-item label="月收入">{{ detailData.monthlyIncome }}</el-descriptions-item>
        <el-descriptions-item label="婚恋状态">{{ detailData.maritalStatus }}</el-descriptions-item>
        <el-descriptions-item label="VIP等级">
          <el-tag v-if="detailData.vipLevel == 0" type="info">普通</el-tag>
          <el-tag v-else-if="detailData.vipLevel == 1" type="warning">VIP1</el-tag>
          <el-tag v-else-if="detailData.vipLevel == 2" type="success">VIP2</el-tag>
          <el-tag v-else type="danger">VIP3</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="注册日期">{{ parseTime(detailData.registrationDate, '{y}-{m}-{d}') }}</el-descriptions-item>
        <el-descriptions-item label="性格描述" :span="2">{{ detailData.personality }}</el-descriptions-item>
        <el-descriptions-item label="兴趣爱好" :span="2">{{ detailData.hobbies }}</el-descriptions-item>
        <el-descriptions-item label="自我介绍" :span="2">{{ detailData.selfIntroduction }}</el-descriptions-item>
      </el-descriptions>
    </el-dialog>

    <!-- 人员导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip">
            <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的人员数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align:baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMember, getMember, delMember, addMember, updateMember } from "@/api/dating/member";
import { autoMatch } from "@/api/dating/match";
import { getToken } from "@/utils/auth";
import ImageUpload from "@/components/ImageUpload";
import RegionSelect from "@/components/RegionSelect";

export default {
  name: "Member",
  dicts: ['dating_member_status'],
  components: {
    ImageUpload,
    RegionSelect
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 婚恋人员信息表格数据
      memberList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 详情对话框
      detailOpen: false,
      detailData: {},
      // 活动标签页
      activeTab: 'basic',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        memberNo: null,
        nickName: null,
        gender: null,
        phone: null,
        city: null,
        memberStatus: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // memberNo: [
        //   { required: true, message: "人员编号不能为空", trigger: "blur" }
        // ],
        nickName: [
          { required: true, message: "昵称不能为空", trigger: "blur" }
        ],
        gender: [
          { required: true, message: "性别不能为空", trigger: "change" }
        ],
        phone: [
          { required: true, message: "手机号码不能为空", trigger: "blur" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ],
        email: [
          {
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: ["blur", "change"]
          }
        ]
      },
      // 人员导入参数
      upload: {
        // 是否显示弹出层（人员导入）
        open: false,
        // 弹出层标题（人员导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的人员数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/dating/member/importData"
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询婚恋人员信息列表 */
    getList() {
      this.loading = true;
      listMember(this.queryParams).then(response => {
        this.memberList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        memberId: null,
        memberNo: null,
        realName: null,
        gender: null,
        birthDate: null,
        age: null,
        height: null,
        weight: null,
        phone: null,
        email: null,
        wechat: null,
        qq: null,
        province: null,
        city: null,
        district: null,
        regionIds: [],
        address: null,
        education: null,
        major: null,
        school: null,
        workUnit: null,
        position: null,
        monthlyIncome: null,
        annualIncome: null,
        maritalStatus: "未婚",
        hasChildren: "0",
        childrenCount: null,
        personality: null,
        hobbies: null,
        selfIntroduction: null,
        avatar: null,
        photos: null,
        mateAgeMin: 18,
        mateAgeMax: 60,
        mateHeightMin: 150,
        mateHeightMax: 200,
        mateEducation: null,
        mateIncomeMin: null,
        mateLocation: null,
        mateRequirement: null,
        registrationDate: null,
        memberStatus: "1",
        vipLevel: 0,
        vipExpireDate: null,
        consultantId: null,
        remark: null
      };
      this.activeTab = 'basic';
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.memberId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加婚恋人员信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const memberId = row.memberId || this.ids
      getMember(memberId).then(response => {
        this.form = response.data;
        // 构造regionIds数组用于级联选择器回显
        this.buildRegionIds();
        this.open = true;
        this.title = "修改婚恋人员信息";
      });
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      this.detailData = row;
      this.detailOpen = true;
    },
    /** 双击行查看详情 */
    handleRowDblClick(row) {
      this.reset();
      getMember(row.memberId).then(response => {
        this.form = response.data;
        // 构造regionIds数组用于级联选择器回显
        this.buildRegionIds();
        this.open = true;
        this.title = "查看婚恋人员信息";
      });
    },
    /** 匹配按钮操作 */
    handleMatch(row) {
      this.$confirm('是否为该人员执行自动匹配?', "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        autoMatch(row.memberId, 5).then(response => {
          this.$modal.msgSuccess(response.msg);
          this.$router.push('/dating/match');
        });
      }).catch(() => {});
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.memberId != null) {
            updateMember(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMember(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const memberIds = row.memberId || this.ids;
      this.$confirm('是否确认删除婚恋人员信息编号为"' + memberIds + '"的数据项？', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delMember(memberIds);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('dating/member/export', {
        ...this.queryParams
      }, `member_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "人员导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('dating/member/importTemplate', {
      }, `member_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    // 地区选择变化处理
    handleRegionChange(regionIds) {
      this.form.regionIds = regionIds;
      // 同时更新province、city、district字段，保持兼容性
      if (regionIds && regionIds.length > 0) {
        // 这里需要根据regionIds获取地区名称
        // 可以通过调用API获取，或者从组件中获取
        this.getRegionNames(regionIds);
      } else {
        this.form.province = null;
        this.form.city = null;
        this.form.district = null;
      }
    },
    // 根据地区ID获取地区名称（现在后端已处理，前端无需额外处理）
    async getRegionNames(regionIds) {
      // 后端已经处理了地区ID到地区名称的转换
      // 这里保留方法以便后续扩展
      console.log('选择的地区ID:', regionIds);
    },
    // 构造regionIds数组（用于编辑时回显）
    buildRegionIds() {
      // 如果后端已经返回了regionIds，直接使用
      if (this.form.regionIds && this.form.regionIds.length > 0) {
        return;
      }

      // 否则根据provinceId、cityId、districtId构造
      const regionIds = [];
      if (this.form.provinceId) {
        regionIds.push(this.form.provinceId);
      }
      if (this.form.cityId) {
        regionIds.push(this.form.cityId);
      }
      if (this.form.districtId) {
        regionIds.push(this.form.districtId);
      }
      this.form.regionIds = regionIds;
    }
  }
};
</script>
